<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内置对象</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
    <script>
        // Math对象==========================
        console.log(Math.PI);

        console.log(Math.abs(12));
        console.log(Math.abs(-13));

        console.log(Math.ceil(12.2));
        console.log(Math.ceil(-12.2));

        console.log(Math.floor(12.2));
        console.log(Math.floor(-12.2));

        console.log(Math.round(3.76))
        console.log(Math.round(-3.76))

        console.log(Math.max(23, -9, 55, 134, -77));
        console.log(Math.min(23, -9, 55, 134, -77));

        let arr = [23, -9, 55, 134, -77];
        console.log(Math.max(arr));
        console.log(Math.max(...arr));

        console.log(Math.pow(2, 8));

        console.log(Math.sqrt(2));

        console.log(Math.exp(2));

        console.log(Math.log(10));

        console.log(Math.sin(Math.PI/6));  // 30度
        console.log(Math.cos(Math.PI/6));


        console.log(Math.random());

        function randInt(start, end) {
            let num = Math.random();
            num = num * (end - start);
            return Math.floor(num + start);
        }

        let res = [];
        for (let i = 0; i < 20; i++) {
            res.push(randInt(6, 19));
        }
        console.log(res);

        // Date对象==========================
        let now = new Date();
        console.log(now);

        console.log(now.getFullYear());
        console.log(now.getMonth());
        console.log(now.getDate());
        console.log(now.getHours());
        console.log(now.getMinutes());
        console.log(now.getSeconds());

        // http://momentjs.cn/docs/#/parsing/now/
        let today = moment();
        console.log(today);

        console.log(today.format("YYYY-MM-DD HH:mm:ss"));
        console.log(today.format("YYYY年MM月DD日 H时m分s秒"));

        today = moment("2022-11-10 13:14:15", "YYYY-MM-DD HH:mm:ss");
        console.log(today);

        let nextDay = moment().add(10, 'days');
        console.log(nextDay.format("YYYY-MM-DD HH:mm:ss"));


    </script>
</body>

</html>